package app

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

/**
 * Created with IntelliJ IDEA.
 * User: 令狐飞侠
 * Date: 2021-11-30
 * Description: gin 同步和异步请求
 */

func TestOthers() {
	router := gin.Default()

	// 同步请求
	router.GET("/syn", func(context *gin.Context) {
		time.Sleep(5* time.Second)
		fmt.Println("current URL:", context.Request.URL)
	})

	// 协程实现异步请求
	router.GET("/asyn", func(context *gin.Context) {
		cContext:=context.Copy()
		go func() {
			// 协程的执行间隔
			time.Sleep(5* time.Second)
			fmt.Println("current URL:", cContext.Request.URL)
		}()
	})
	//启动端口8080的服务
	router.Run(":8080")

}